import request, { requestHttp } from "@/utils/request";
import { ReqPage, ResPage } from "@/api/types";
import { UserEntity } from "@/api/system/user";

export interface EvalReviewer {
  id?: number;
  reviewerKey?: string;
  formKey?: string;
  reviewerUserId?: string;
  reviewerType?: string;
  reviewerStatus?: string;
  appraiseUserList?: EvalReviewerUser[];
  createTime?: string;
  updateTime?: string;
}

export interface EvalReviewerUser {
  roleId?: number;
  userId?: number;
  user: UserEntity;
}

export interface ReqEvalReviewerParams extends ReqPage {
  formKey: string;
  nickName: "";
  noticeStatus?: "";
  reviewerStatus?: "";
}

/**
 * 获取评价人列表
 */
export function listEvalReviewer(params: ReqEvalReviewerParams) {
  return requestHttp.get<ResPage<EvalReviewer>>("/form/eval/reviewer/page", params);
}

export interface ReviewerInfo {
  /**
   * 评价人列表
   */
  appraiseUserList: EvalReviewerUser[];

  /**
   * 是否可以评价
   */
  canAppraise: boolean;

  token: string;

  userId: number;

  reviewerKey: string;

  formKey: string;
}

/**
 * 获取被评价用户
 */
export function getReviewerInfo(reviewerKey: string) {
  return requestHttp.get<ReviewerInfo>(`/form/eval/reviewer/info`, { reviewerKey });
}

/**
 * 导出excel
 */
export function exportReviewer(param: ReqEvalReviewerParams) {
  return request({
    url: "/form/eval/reviewer/export",
    method: "get",
    params: param,
    responseType: "blob"
  });
}

export interface NoticeParam {
  formKey: string;
  all?: boolean;
  reviewerIds?: number[];
  params: any;
}

/**
 * 发送通知
 */
export function sendNotify(data: NoticeParam) {
  return requestHttp.post(`/form/eval/reviewer/notice`, data);
}

/**
 * 清除数据
 */
export function clearData(formKey: string, ids: number[]) {
  return requestHttp.post(`/form/eval/reviewer/clearData`, { formKey, ids });
}
